using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class ProfileClickContentGridCtrl : ProfileInfoItemBase
	{
		public enum CtrlType
		{
			tencentWeibo
		}
		private const string TAG = "ProfileTxtContentCtrl";
		private const int cNMaxCacheCnt = 5;
		private ProfileClickContentGridCtrl.CtrlType mCtrlType;
		private bool mBIsFirstLoaded = true;
		private static List<ProfileClickContentGridCtrl> sItemsCached = new List<ProfileClickContentGridCtrl>();
		internal StackPanel LayoutRoot;
		internal TextBlock txtTitle;
		internal Button btnContent;
		internal TextBlock txtContent;
		private bool _contentLoaded;
		public ProfileClickContentGridCtrl()
		{
			base.set_Margin(new Thickness(0.0, 25.0, 0.0, 0.0));
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.ProfileClickContentGridCtrl_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ProfileClickContentGridCtrl_Unloaded));
		}
		private void ProfileClickContentGridCtrl_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void ProfileClickContentGridCtrl_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.mCtrlType == ProfileClickContentGridCtrl.CtrlType.tencentWeibo)
			{
				string mStrInfo = base.InfoData.mStrInfo2;
				string text = "";
				string text2 = "";
				BasePage rootPage = ToolFunction.GetRootPage();
				if (rootPage is ContactDetailViewForAll)
				{
					ContactDetailViewForAll contactDetailViewForAll = rootPage as ContactDetailViewForAll;
					text = contactDetailViewForAll.mContactDitailViewArgs.mContact.strUsrName;
				}
				int num = base.InfoData.mStrInfo1.IndexOf("@");
				if (num > 0)
				{
					string text3 = base.InfoData.mStrInfo1.Substring(num, base.InfoData.mStrInfo1.get_Length() - num);
					if (text3.EndsWith(")"))
					{
						text3 = text3.Substring(0, text3.get_Length() - 1);
					}
					text2 = text3;
				}
				ToolFunction.GotoPageForUserControl("/Source/UI/Util/CommmonWebView.xaml", new object[]
				{
					mStrInfo,
					text,
					text2
				}, false);
			}
		}
		protected override void RefreshItem()
		{
			if (base.InfoData == null)
			{
				base.set_Visibility(1);
				return;
			}
			base.set_Visibility(0);
			this.txtTitle.set_Text(base.InfoData.mStrTitle);
			this.txtContent.set_Text(base.InfoData.mStrInfo1);
		}
		public void SetContent(string strTitle, string strInfo1, string strInfo2 = null, ProfileInfoKind infoKind = ProfileInfoKind.Kind_None)
		{
			ProfileInfoData infoData = new ProfileInfoData
			{
				mStrTitle = strTitle,
				mStrInfo1 = strInfo1,
				mStrInfo2 = strInfo2,
				mInfoKind = infoKind
			};
			base.InfoData = infoData;
		}
		public override void Collect()
		{
			base.InfoData = null;
			base.set_Visibility(1);
			this.txtTitle.set_Text("");
			this.txtContent.set_Text("");
		}
		public static ProfileClickContentGridCtrl GetOneItem()
		{
			if (ProfileClickContentGridCtrl.sItemsCached != null && ProfileClickContentGridCtrl.sItemsCached.get_Count() != 0)
			{
				ProfileClickContentGridCtrl profileClickContentGridCtrl = Enumerable.First<ProfileClickContentGridCtrl>(ProfileClickContentGridCtrl.sItemsCached);
				ProfileClickContentGridCtrl.sItemsCached.RemoveAt(0);
				if (profileClickContentGridCtrl.get_Parent() == null)
				{
					return profileClickContentGridCtrl;
				}
			}
			return new ProfileClickContentGridCtrl();
		}
		public static int GetCacheCnt()
		{
			if (ProfileClickContentGridCtrl.sItemsCached == null)
			{
				return 0;
			}
			return ProfileClickContentGridCtrl.sItemsCached.get_Count();
		}
		public static void PushOneItem(ProfileClickContentGridCtrl item)
		{
			if (item == null)
			{
				return;
			}
			if (ProfileClickContentGridCtrl.sItemsCached == null)
			{
				ProfileClickContentGridCtrl.sItemsCached = new List<ProfileClickContentGridCtrl>();
			}
			if (item.get_Parent() != null)
			{
				Panel panel = item.get_Parent() as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(item);
				}
			}
			item.Collect();
			if (ProfileClickContentGridCtrl.sItemsCached.get_Count() >= 5)
			{
				return;
			}
			ProfileClickContentGridCtrl.sItemsCached.Add(item);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ProfileInfo/ProfileClickContentGridCtrl.xaml", 2));
			this.LayoutRoot = (StackPanel)base.FindName("LayoutRoot");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.btnContent = (Button)base.FindName("btnContent");
			this.txtContent = (TextBlock)base.FindName("txtContent");
		}
	}
}
